<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Rotating Div</title>
    <style>
        .container {
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        #rotatingDiv {
            width: 200px;
            height: 200px;
            background-color: #fbdb00;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: transform 0.5s ease-in-out;
        }
    </style>
</head>
<body>
<div class="container">
    <div id="rotatingDiv" onclick="rotate()">点我旋转</div>
</div>
<script>
    const rotatingDiv = document.getElementById("rotatingDiv");
    let rotationAngle = 0;

    function delay(time) {
        return new Promise(resolve => setTimeout(resolve, time));
    }

    async function rotate() {
        await delay(2000); // 等待5秒
        // 切换角度，每次点击在0度和180度之间切换
        rotationAngle = (rotationAngle + 180) % 360; // 使用模运算确保角度在0-359之间
        rotatingDiv.style.transform = `rotate(${rotationAngle}deg)`;
    }
</script>
</body>
</html>